package com.iweb.pojo;

import java.io.IOException;

import java.text.SimpleDateFormat;

import java.util.Date;


import com.fasterxml.jackson.core.JsonGenerator;

import com.fasterxml.jackson.core.JsonProcessingException;

import com.fasterxml.jackson.databind.JsonSerializer;

import com.fasterxml.jackson.databind.SerializerProvider;

/**

  * Date 转为json 格式时格式化时间格式

  * @author dell

  *

  */



public class JsonDateSerializer extends JsonSerializer<Date> {

 private SimpleDateFormat dateFormat=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

 @Override
public void serialize(Date date, JsonGenerator gen, SerializerProvider provider)

 throws IOException, JsonProcessingException {

 String value = "";

if(null !=date){

 value = dateFormat.format(date);
 }

 gen.writeString(value);

 }

}
